<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/formvalid.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            #panel{width:90%;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="mgrole_edit_frm" name="mgrole_edit_frm">
                <input type="hidden" name="rolelevel" id="rolelevel" value="" />
                <input type="hidden" name="remark" id="remark" value="" />
                <input type="hidden" name="roleid" id="roleid" value="" />
                <table>
                    <tr>
                        <th colspan="3">&nbsp;编辑管理员角色</th>
                    </tr>
                    <tr>
                        <td width="21%"  class="r">角色名称：</td>
                        <td width="30%">
                            <input name="rolename" type="text" id="rolename" tabindex="1" style="width:200px;" maxlength="30" valid="required" errmsg="角色名称不能为空!" />*</td>
                        <td width="49%"><div id="err_rolename"></div></td>
                    </tr>
                    <tr>
                        <td  class="r">角色描述：</td>
                        <td>
                            <textarea name="J_remark" id="J_remark" cols="25" rows="5"  style="width:200px;" valid="required|limit" min="2" max="120" errmsg="角色描述不能为空!|描述字符数请控制在2-120之间"></textarea>        
                            *</td>
                        <td><div id="err_J_remark"></div></td>
                    </tr>
                    <tr>
                        <td  class="r">管理模块：</td>
                        <td>
                            <script type="text/javascript" src="../js/rolecfg.js"></script>
                        </td>
                        <td>*</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="c">&nbsp;
                            <input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="更新" onClick="ROLE.submit();" />
                            <input name="backBtn" type="button" class="button medium gray" id="backBtn" tabindex="7" value="返回" onClick="ROLE.back();" />
                        </td>
                        <td> </td>
                    </tr>
                </table>
            </form>
        </div>
        <script type="text/javascript">
            var id = ut.get('roleid');
            var frm = ut.e('mgrole_edit_frm');
            initValid(frm);
            var ROLE={
                init:function(){
                    $('#roleid').val(id);
                    $.get('../app/admin/query_role.shtm','roleid='+id+'&t='+ut.r(),function(x){
                        if($.trim(x.toString())<9){ut.m('数据读取错误.');return;}
                        $('#rolename').val(x.rolename);
                        $('#J_remark').val(x.remark);
                        var lva = x.rolelevel.substring(1,x.rolelevel.length-1).split('-');
                        for(var a in lva){
                            ut.e('lv' + lva[a]).checked = 'checked';
                        }
                    });  
                },
                submit:function(){
                    var rl = ut.getselv('level'); // see rolecfg.js
                    if(va.isnull(rl)){ut.m('没有任何授权，请选择模块管理权限.');return;}
                    $('#rolelevel').val('-'+rl+'-');
                    var $rb=$('#submitBtn');
                    if(validator(frm)){
                        $rb.attr('disabled','disabled');
                        $('#remark').val($('#J_remark').val());
                        $.get('../app/admin/update_role.shtm',$('#mgrole_edit_frm').serialize(),function(x){
                            var r = $.trim(x);
                            if(r=='ok'){
                                ut.m('更新成功!');
                                ROLE.back();
                            }else{
                                ut.m('操作失败.!'+r);
                                frm.reset();
                                $rb.removeAttr('disabled');
                            }
                        });
                    }   
                },
                back:function(){ ut.reload('mgrole.html?'+ut.r());}
            };  
   
            ROLE.init();
        </script>
    </body>
</html>
